/**
 * 
 */
package leetCode;

import javax.xml.soap.Node;

import leetCode.SecondMinimumNodeInaBinaryTree.TreeNode;

/**
 * @author zhongfang
 *
 */
public class TrimaBinarySearchTree {
	public class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode(int x) {
			val = x;
		}
	}
    public TreeNode trimBST(TreeNode root, int L, int R) {
    	if(root==null){
    		return null;
    	}
    	TreeNode left=trimBST(root.left, L, R);
    	TreeNode right=trimBST(root.right, L, R);
        if(root.val<=R&&root.val>=L){
        	root.left=left;
        	root.right=right;
        	return root;
        }else if(left==null){
        	return right;
        }else if(right==null){
        	return left;
        }
		return null;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
